package com.hushao.aimi.controller;

import com.hushao.aimi.common.ServerResponse;
import com.hushao.aimi.service.ProductService;
import com.hushao.aimi.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 首页
 * @author: 胡少
 * @create: 2018-06-18 11:25
 **/
@Slf4j
@RestController
@RequestMapping("/")
@Api(value = "首页服务")
public class MainController {
    @Autowired
    private UserService userService;
    @Autowired
    private ProductService productService;

    @ApiOperation(value = "首页信息")
    @GetMapping
    public ServerResponse main(Model model){

        //用户数量
        Long uCount=userService.count();
        model.addAttribute("uCount",uCount);
        //商品数量
        Long pCount=productService.count();
        model.addAttribute("pCount",pCount);

        return ServerResponse.Success(model);
    }
}
